<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class GiftsController extends AppController {

    var $layout = 'subpage';
    var $uses = array(
        'Basket', 'Gift', 'Comment', 'Share', 'Logo', 'Banner', 'Giftphoto'
    );
    var $components = array(
        'Security'
    );
    var $helpers = array('Cache');
    var $cacheAction = array(
        'index' => 120
    );

    function index($page = 1) {
        $this->set('title_for_layout', 'www.Hong3ly.com .:.  trái cây việt | trái cây viêt nam | trái cây ngoại nhập | trái cây | giỏ trái cây | trái cây tươi');
        $page = array_key_exists('page', $this->params['named']) ? $this->params['named']['page'] : $page;
        $conditions = array(
            'Gift.published' => 1,
        );
        $this->paginate = array(
            'fields' => array('Gift.id, Gift.title, Gift.alias, Gift.price,Gift.images_small'),
            'conditions' => $conditions,
            'limit' => 9,
            'order' => array(
                'Gift.id' => 'DESC'
            ),
        );
        $data = $this->paginate('Gift');
        $this->set('total', $this->params['paging']['Gift']['count']);
        $this->set('data', $data);
        $this->set('best_buy_product', $this->Basket->getBestBuy());
        $this->set('lastestShare', $this->Share->getLastestShare());
        $this->set('limit_page', $this->paginate['limit']);
        $this->set('basket_image_thumb_url_path', Configure::read('basket_image_thumb_url_path'));
        $this->set('gift_image_thumb_url_path', Configure::read('gift_image_thumb_url_path'));
        $this->set('logo', $this->Logo->getLogo());
        $this->set('logo_thumb_url_path', Configure::read('logo_thumb_url_path'));
        $this->set('banners_customers', $this->Banner->getBanners());
        $this->set('banner_image_thumb_url_path', Configure::read('banner_image_thumb_url_path'));
        $this->set('start_page', $page);
    }

    function detail($id) {
        $content = $this->Gift->read(array('id', 'title', 'images_large','images_small', 'description', 'price', 'note'), $id);

        $page = array_key_exists('page', $this->params['named']) ? $this->params['named']['page'] : 1;
        $conditions = array(
            'Comment.published' => 1,
            'Comment.module' => 'gift',
            'Comment.module_unique_id' => $id,
        );
        $this->paginate = array(
            'fields' => array("DATE_FORMAT(Comment.created,'%d-%m-%Y %h:%h %p') AS 'Comment.created', Comment.id, Comment.subject, Comment.content, User.id, User.name"),
            'conditions' => $conditions,
            'limit' => 5,
            'order' => array(
                'Comment.id' => 'DESC'
            ),
        );
        $data_comments = $this->paginate('Comment');

        $this->set('total', $this->params['paging']['Comment']['count']);
        $this->set('data_comments', $data_comments);

        $this->set('title_for_layout', "Quà cưới &gt;&gt;{$content['Gift']['title']}- trái cây việt | trái cây viêt nam | trái cây ngoại nhập | trái cây | giỏ trái cây | trái cây tươi");
        $this->set('content', $content);
        $this->set('limit_page', $this->paginate['limit']);
        $this->set('lastestShare', $this->Share->getLastestShare());
        $this->set('best_buy_product', $this->Basket->getBestBuy());
        $this->set('others', $this->Gift->getOthers($id));
        $this->set('gift_id', $id);
        $this->set('photos', $this->Giftphoto->getPhotos($id));
        $this->set('gift_gallery_thumb_url_path', Configure::read('gift_gallery_thumb_url_path'));
        $this->set('gift_image_thumb_url_path', Configure::read('gift_image_thumb_url_path'));
        $this->set('logo', $this->Logo->getLogo());
        $this->set('logo_thumb_url_path', Configure::read('logo_thumb_url_path'));
        $this->set('basket_image_thumb_url_path', Configure::read('basket_image_thumb_url_path'));
        $this->set('banners_customers', $this->Banner->getBanners());
        $this->set('banner_image_thumb_url_path', Configure::read('banner_image_thumb_url_path'));
    }

}

?>
